package com.qriver.auth.client.config;


import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Value;

import com.qriver.auth.common.utils.jwt.RsaKeyHelper;

/**
 * 参数配置，token在header的key和pubKeyByte
 * Created by ace on 2017/9/15.
 */
public class UserAuthConfig {
	//gate 模块中定义
    //@Value("${auth.user.token-header}")
	@Value("Authorization")
    private String tokenHeader;

	private byte[] pubKeyByte;

    public String getTokenHeader() {
        return tokenHeader;
    }

    public void setTokenHeader(String tokenHeader) {
        this.tokenHeader = tokenHeader;
    }

    public String getToken(HttpServletRequest request){
        return request.getHeader(this.getTokenHeader());
    }

    public byte[] getPubKeyByte() {
    	//临时
        //return "pubKeyByte-test".getBytes();//pubKeyByte;
        Map<String, byte[]> keyMap = null;
		try {
			keyMap = RsaKeyHelper.generateKey("xx1WET12^%3^(WE45");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return keyMap.get("pub");
    }

    public void setPubKeyByte(byte[] pubKeyByte) {
        this.pubKeyByte = pubKeyByte;
    }
    public static void main(String[] args) {
		System.out.println("pubKeyByte-test".getBytes());
		System.out.println();
	}
}
